package com.server.server_a10.controller.securitySystem;

import com.server.server_a10.entity.Inform;
import com.server.server_a10.entity.securitySystem.Door;
import com.server.server_a10.mapper.DoorMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api("前后端交互测试用例")
public class DoorHandle {
    @Autowired
    DoorMapper doorMapper;
    @GetMapping(value = "/test_doorInf")
    @ApiOperation("这个接口是安保设备（门）的测试用例，暂无入参，回参为门的信息")
    public Door getDoorInfDemo(){
        return new Door(10001L,false);
    }

    @GetMapping(value = "/getDoorsByHomeId")
    public Inform getDoorByHomeId(@RequestBody Map<String,Integer> request){
        Inform inform = new Inform();
        int id = request.get("id");

        List<Door> doors = doorMapper.getDoorByHomeId(id);

        if (doors.isEmpty()){
            inform.setCode(100);
            inform.setMsg("这个家没有门，家人们都是翻窗而入");
        }else {
            inform.setCode(200);
            inform.setMsg("门的信息获取成功");
            inform.setData(doors);
        }

        return inform;
    }


    @PostMapping(value = "/getDoorsByHomeId")
    public Inform getDoorByHomeIdPost(@RequestBody Map<String,Integer> request){
        Inform inform = new Inform();
        int id = request.get("id");

        List<Door> doors = doorMapper.getDoorByHomeId(id);

        if (doors.isEmpty()){
            inform.setCode(100);
            inform.setMsg("这个家没有门，家人们都是翻窗而入");
        }else {
            inform.setCode(200);
            inform.setMsg("门的信息获取成功");
            inform.setData(doors);
        }

        return inform;
    }
}
